﻿using Mimas.Framework.Shared.Data.DataTransferObjects;
using Mimas.Framework.Shared.Data.EnumObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace Mimas.Core.Current
{
  public class UserInfo
  {
    private static string CurrentUserSessionKey = "{192846F1-7BB1-4F93-8CBE-D405582433AD}";

    public static CurrentUserDTO CurrentUser
    {
      get
      {
        if (HttpContext.Current.Session[CurrentUserSessionKey] != null)
          return (CurrentUserDTO)HttpContext.Current.Session[CurrentUserSessionKey];
        else
          return new CurrentUserDTO() { UserType = EUserType.Guest };
      }
      set { HttpContext.Current.Session[CurrentUserSessionKey] = value; }
    }

    public static bool UserLogOut()
    {
      try
      {
        HttpContext.Current.Session.Clear();
        HttpContext.Current.Session.Abandon();
        return true;
      }
      catch
      {
        return false;
      }
    }
  }
}
